package com.googlecode.spruce.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "host")
public class Host implements Serializable
{
    /** Serial ID **/
    private static final long serialVersionUID = -3223249345879576772L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "name")
    private String name;

    @Column(name = "ip_address")
    private String ipAddress;

    @ManyToOne
    @JoinColumn(name = "os_id")
    private OperatingSystem operatingSystem;

    @OneToMany(mappedBy = "host")
    private Set<ServiceGroupSchedule> serviceGroupSchedules;

    @OneToMany(mappedBy = "host")
    private Set<ServiceResult> serviceResults;

    /**
     * @return the id
     */
    public Integer getId()
    {
        return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(final Integer id)
    {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName()
    {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(final String name)
    {
        this.name = name;
    }

    /**
     * @return the ipAddress
     */
    public String getIpAddress()
    {
        return ipAddress;
    }

    /**
     * @param ipAddress
     *            the ipAddress to set
     */
    public void setIpAddress(final String ipAddress)
    {
        this.ipAddress = ipAddress;
    }

    public OperatingSystem getOperatingSystem()
    {
        return operatingSystem;
    }

    public void setOperatingSystem(final OperatingSystem operatingSystem)
    {
        this.operatingSystem = operatingSystem;
    }

    /**
     * @return the serviceGroupSchedules
     */
    public Set<ServiceGroupSchedule> getServiceGroupSchedules()
    {
        return serviceGroupSchedules;
    }

    /**
     * @param serviceGroupSchedules
     *            the serviceGroupSchedules to set
     */
    public void setServiceGroupSchedules(final Set<ServiceGroupSchedule> serviceGroupSchedules)
    {
        this.serviceGroupSchedules = serviceGroupSchedules;
    }

    /**
     * @return the serviceResults
     */
    public Set<ServiceResult> getServiceResults()
    {
        return serviceResults;
    }

    /**
     * @param serviceResults
     *            the serviceResults to set
     */
    public void setServiceResults(final Set<ServiceResult> serviceResults)
    {
        this.serviceResults = serviceResults;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        Host other = (Host) obj;
        if (ipAddress == null)
        {
            if (other.ipAddress != null)
            {
                return false;
            }
        }
        else if (!ipAddress.equals(other.ipAddress))
        {
            return false;
        }
        if (name == null)
        {
            if (other.name != null)
            {
                return false;
            }
        }
        else if (!name.equals(other.name))
        {
            return false;
        }
        return true;
    }

}
